import com.spi.demo.NumOperate;

import java.util.Iterator;
import java.util.ServiceLoader;

public class NumOperateTest {

    public static void main(String[] args) {

        // SPI机制，寻找所有的实现类，顺序执行
        ServiceLoader<NumOperate> loader = ServiceLoader.load(NumOperate.class);
        Iterator<NumOperate> iterator = loader.iterator();

        while (iterator.hasNext()){
            // 获取下一个元素；
            NumOperate numOperate = iterator.next();
            System.out.println(numOperate.exec(5, 2));
        }


//        if (iterator.hasNext()) {
//            NumOperate numOperate = iterator.next();
//            System.out.println(numOperate.exec(5, 2));
//        } else {
//            throw new RuntimeException("classpath中未找到cn.bigcoder.spi.operate.NumOperate实现类");
//        }
    }
}
